package cn.com.joyplus.wechat.configuration;

import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
 * Created by 王灏川(wangrs@qq.com) on 2017/8/11 0011.
 */
@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class ApplicationSecurity extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().
                antMatchers("/","/public/**","/wx-event-dispatcher/listener").permitAll().
                anyRequest().fullyAuthenticated().
                and().
                    formLogin().loginPage("/login").defaultSuccessUrl("/").
                    failureUrl("/login?error").successForwardUrl("/").permitAll().
                and()
                    .logout().logoutSuccessUrl("/").permitAll();
        http.csrf().disable();
    }

    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication().withUser("admin").password("93HmCM+Kdt4JccuWPmWf+Q==")
                .roles("ADMIN", "USER");
    }

}
